package com.zxp.quartz.jdktimer;

import lombok.SneakyThrows;

import java.lang.management.ManagementFactory;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;

/**
 * @Author: qingshan
 * @Date: 2019/9/3 22:31
 * @Description: 咕泡学院，只为更好的你
 */
public class Task extends TimerTask {

    private String name;

    public Task(String name) {
        this.name = name;
    }

    /**
     * 此计时器任务要执行的操作。
     */
    @SneakyThrows
    public void run() {
        Date executeTime = new Date(this.scheduledExecutionTime());
        String dateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println( ManagementFactory.getRuntimeMXBean().getName() +" "+name+" 开始执行任务：" + new Date());
        Thread.sleep(3000);
        String dateStr2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println(ManagementFactory.getRuntimeMXBean().getName() +" "+name+ " 任务执行结束：" + dateStr2);
    }
}
